<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文章审核</title>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/static/css/global.css">
    <link rel="stylesheet" href="/static/css/user.css">
</head>
<body>

<div class="breadcrumb" style="margin: 20px">
    <span class="layui-breadcrumb">
        <a href="/admin/users">首页</a>
        <a href="/admin/articles">文章编辑</a>
        <a><cite>文章审核</cite></a>
    </span>
</div>
<!--中间内容部分-->
<div class="layui-container">
    <!--新闻列表-->
    <div class="layui-row main" style="margin-top: 20px">

        <form class="layui-form" action="">
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">文章ID：</label>
                <div class="layui-input-block">
                    <input type="text" name="id" required lay-verify="required"
                           value="{{ article.id }}"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章标题：</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required lay-verify="required"
                           value="{{ article.title }}"
                           placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章类别：</label>
                <div class="layui-input-inline">
                    <select name="category_id" lay-verify="required" lay-search="">
                        <option value="">请选择分类</option>
                        {% for cate in cate_list %}
                            <option value="{{ cate.id }}"
                                    {% if article.category_id == cate.id %} selected {% endif %}
                            >{{ cate.name }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">摘要：</label>
                <div class="layui-input-block">
                    <textarea name="digest" placeholder="请输入内容"
                              class="layui-textarea"> {{ article.digest }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上传图像：</label>
                <div class="layui-input-block">
                    <input type="text" name="image_url" class="article_img_url" style="display: none"
                           value="{{ article.index_image_url }}">
                    <button type="button" class="layui-btn" id="test1">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-input-block">
                    <img src="{{ article.index_image_url }}" alt="文章图片" class="article_img" style="display: block">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="rich_content">内容：</label>
                <div class="layui-input-block">
                    <input class="input_area" id="rich_content" name="content" value="{{ article.content }}"
                           style="height: 700px">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审核通过</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="0" title="通过"
                           {% if article.status == 0 %}checked{% endif %}>
                    <input type="radio" name="status" value="-1" title="不通过"
                           {% if article.status == -1 %}checked{% endif %}>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">拒绝原因：</label>
                <div class="layui-input-block">
                    <textarea name="reason" placeholder="请输入原因" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/static/layui/layui.js"></script>
<script src="/static/pear/component/pear/pear.js"></script>
<script src="/static/tinymce/js/tinymce/tinymce.min.js"></script>
<script>
    layui.use([
        'jquery', 'form', 'toast', 'layer', 'element', 'tab'], function() {

        var layer = layui.layer;
        var tab = layui.tab;
        var form = layui.form;
        var $ = layui.jquery;
        var toast = layui.toast;
        tinymce.init({
            selector: '#rich_content',
            language: 'zh_CN', //调用放在langs文件夹内的语言包
            //工具栏上面的补丁按钮
            plugins: [
                'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
                'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
                'save table contextmenu directionality template paste textcolor',
                'codesample imageupload',
            ],
            //工具栏的补丁按钮
            toolbar: 'insertfile undo redo | \
     styleselect | \
     bold italic | \
     alignleft aligncenter alignright alignjustify | \
     bullist numlist outdent indent | \
     link image | \
     print preview media fullpage | \
     forecolor backcolor emoticons |\
     codesample fontsizeselect fullscreen |\
     imageupload',
            //字体大小
            fontsize_formats: '10pt 12pt 14pt 18pt 24pt 36pt',
            //按 tab 不换行
            nonbreaking_force_tab: true,
            imageupload_url: '/user/submit-image',
        });

        form.on('submit(formDemo)', function(form) {
            console.log(form.field);
            fetch('/admin/articles_verify', {
                method: 'PUT',
                headers: {'content-type': 'application/json'},
                body: JSON.stringify(form.field),
            }).then(function(response) {
                return response.json();
            }).then(function(ret) {
                console.log(ret);
                if (ret.status === 'success') {
                    toast.success({message: ret.message});
                    // 关闭当前页
                    // 关闭当前页失败
                    {#parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页#}
                }
            });
            return false;
        });
    });

    // 细节优化 通过时不显示拒绝原因
    // 建议通过 jquery 进行操作

</script>
</body>
</html>
